package com.wsc.castle;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

import com.wsc.castle.ui.sprites.Enemy;

public class GameView extends SurfaceView {

	private SurfaceHolder holder;
	private GameThread gameThread;

	private Enemy enemy;

	public GameView(Context context) {
		super(context);
		gameThread = new GameThread(this);
		holder = getHolder();

		holder.addCallback(new SurfaceHolder.Callback() {
			public void surfaceDestroyed(SurfaceHolder holder) {
				boolean retry = true;
				gameThread.setRunning(false);
				while (retry) {
					try {
						gameThread.join();
						retry = false;
					} catch (InterruptedException e) {
					}
				}
			}

			public void surfaceCreated(SurfaceHolder holder) {
				gameThread.setRunning(true);
				gameThread.start();
			}

			public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
			}
		});

		enemy = new Enemy(this);
	}

	protected void onDraw(Canvas canvas) {
		canvas.drawColor(Color.GRAY);
		enemy.onDraw(canvas);
	}
}